package com.mayikt.handler;

import com.alibaba.fastjson.JSONObject;
import com.mayikt.entity.UserDO;
import com.mayikt.mapper.UserMapper;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.util.ShardingUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Name WeChatActivityJob
 * @Author 枫火
 * @Date 2021/5/23 17:30
 * @Description 定时任务类
 **/
@Component
@Slf4j
public class WeChatActivityJob {

    @Autowired
    private UserMapper userMapper;
    @Value("${mayikt.member.job.WeChatActivitiePageSize}")
    private Integer pageSize;

    /**
     * @param param
     * @return
     * @XxlJob 该任务的名称id
     */
    @XxlJob("weChatActivityJobHandler")
    public ReturnT<String> weChatActivityJobHandler(String param) {
        ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
        int index = shardingVO.getIndex();
//        int startIndex = ((index + 1) - 1) * pageSize;
        int startIndex = index * pageSize;
//        log.info(">>>定时任务开始触发<<<param:{},index:{}", param, index);
        List<UserDO> userDos = userMapper.selectByOpenIdNotIsNull(startIndex, pageSize);
        log.info("userDos:" + JSONObject.toJSONString(userDos));
        return ReturnT.SUCCESS;
    }
}
